// SettingsDialog.cpp : implementation file
//

#include "stdafx.h"
#include "SettingsDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSettingsDialog dialog


CSettingsDialog::CSettingsDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CSettingsDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSettingsDialog)
	m_istransbg = FALSE;
	m_text = _T("");
	m_info = _T("");
	m_rot = _T("");
	m_Adate = 0;
	m_plasD = 0;
	m_plasM = 0;
	m_IsSetlocale = FALSE;
	m_SetlocaleText = _T("");
	//}}AFX_DATA_INIT
	m_isCW=TRUE;
	m_Halign=ALIGN_EDGEWISE;
	m_Valign=ALIGN_EDGEWISE;
	ZeroMemory(&m_lf,sizeof(m_lf));
	m_istransbg=TRUE;
	m_rotation=0;
	CTime T=CTime::GetCurrentTime();
	m_Date=T.Format("%d.%m.%Y");

}


void CSettingsDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSettingsDialog)
	DDX_Control(pDX, IDC_BUTTON_FG, m_fg);
	DDX_Control(pDX, IDC_BUTTON_BG, m_bg);
	DDX_Check(pDX, IDC_CHECK_TRANSBG, m_istransbg);
	DDX_Text(pDX, IDC_EDIT_TEXT, m_text);
	DDX_Text(pDX, IDC_EDIT_INFO, m_info);
	DDX_Text(pDX, IDC_EDIT_ROT, m_rot);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER, m_Adate);
	DDX_Text(pDX, IDC_EDIT_PLAS_D, m_plasD);
	DDX_Text(pDX, IDC_EDIT_PLAS_M, m_plasM);
	DDX_Check(pDX, IDC_CHECK_SETLOCALE, m_IsSetlocale);
	DDX_Text(pDX, IDC_EDIT_SETLOCALE, m_SetlocaleText);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSettingsDialog, CDialog)
	//{{AFX_MSG_MAP(CSettingsDialog)
	ON_BN_CLICKED(IDC_BUTTON_FONT, OnButtonFont)
	ON_BN_CLICKED(IDC_CHECK_TRANSBG, OnCheckTransBG)
	ON_BN_CLICKED(IDC_CHECK_LEFT, OnCheckLeftAlign)
	ON_BN_CLICKED(IDC_CHECK_RIGHT, OnCheckRightAlign)
	ON_BN_CLICKED(IDC_CHECK_EDGEWISE, OnCheckEdgewiseAlign)
	ON_BN_CLICKED(IDC_CHECK_TOP, OnCheckTopAlign)
	ON_BN_CLICKED(IDC_CHECK_H, OnCheckHeighAlign)
	ON_BN_CLICKED(IDC_CHECK_BOTTOM, OnCheckBottomAlign)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSettingsDialog message handlers

void CSettingsDialog::OnButtonFont() 
{
	CFontDialog dlg(&m_lf,CF_SCREENFONTS,NULL,this);
	if (dlg.DoModal() == IDOK)
	{	dlg.GetCurrentFont(&m_lf);
	}		
}


CString CSettingsDialog::LoadString(UINT id)
{
	CString S;
	S.LoadString(id);
	return S;
}


BOOL CSettingsDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	OnCheckTransBG();

	m_info=LoadString(IDS_HELP1);
	m_info+=LoadString(IDS_HELP2);
	m_info+=LoadString(IDS_HELP3);
	m_info+=LoadString(IDS_HELP4);
	m_info+=LoadString(IDS_HELP5);
	m_info+=LoadString(IDS_HELP6);
	CString A=CString("")+(char)0x0D+(char)0x0A;
	m_info.Replace(CString("\n"),A);

	((CButton*)GetDlgItem(IDC_CHECK_LEFT))->SetCheck(m_Halign==ALIGN_LEFT ? 1 : 0);
	((CButton*)GetDlgItem(IDC_CHECK_RIGHT))->SetCheck(m_Halign==ALIGN_RIGHT ? 1 : 0);
	((CButton*)GetDlgItem(IDC_CHECK_EDGEWISE))->SetCheck(m_Halign==ALIGN_EDGEWISE ? 1 : 0);
	((CButton*)GetDlgItem(IDC_CHECK_TOP))->SetCheck(m_Valign==ALIGN_TOP ? 1 : 0);
	((CButton*)GetDlgItem(IDC_CHECK_BOTTOM))->SetCheck(m_Valign==ALIGN_BOTTOM ? 1 : 0);
	((CButton*)GetDlgItem(IDC_CHECK_H))->SetCheck(m_Valign==ALIGN_EDGEWISE ? 1 : 0);


	((CButton*)GetDlgItem(IDC_CHECK_LEFT))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_L));
	((CButton*)GetDlgItem(IDC_CHECK_RIGHT))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_R));
	((CButton*)GetDlgItem(IDC_CHECK_EDGEWISE))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_RL));
	((CButton*)GetDlgItem(IDC_CHECK_TOP))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_T));
	((CButton*)GetDlgItem(IDC_CHECK_BOTTOM))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_B));
	((CButton*)GetDlgItem(IDC_CHECK_H))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_TB));


	((CButton*)GetDlgItem(IDC_RADIO_ANTICLOCKWISE))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_CW));
	((CButton*)GetDlgItem(IDC_RADIO_CLOCKWISE))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_CCW));

	((CButton*)GetDlgItem(IDC_RADIO_PLAS))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_PLAS));
	((CButton*)GetDlgItem(IDC_RADIO_MINUS))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_MINUS));


	double f;

	if (m_rotation>0)
	{	f=((double)m_rotation)/10;
		m_isCW=TRUE;
	} else
	{	f=((double)(-m_rotation))/10;
		m_isCW=FALSE;
	}
	m_rot.Format("%.1f",f);

	((CButton*)GetDlgItem(IDC_RADIO_CLOCKWISE))->SetCheck(m_isCW ? 1 : 0);
	((CButton*)GetDlgItem(IDC_RADIO_ANTICLOCKWISE))->SetCheck(m_isCW ? 0 : 1);


	((CButton*)GetDlgItem(IDC_RADIO_PLAS))->SetCheck(m_isPlas ? 1 : 0);
	((CButton*)GetDlgItem(IDC_RADIO_MINUS))->SetCheck(m_isPlas ? 0 : 1);


	COleDateTime T;
	if (T.ParseDateTime(m_Date))
	{	m_Adate=CTime(T.GetYear(),T.GetMonth(),T.GetDay(),12,0,0);
	} else
	{	m_Adate=CTime::GetCurrentTime();
	}



	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSettingsDialog::OnCheckTransBG() 
{
	UpdateData(TRUE);	
	GetDlgItem(IDC_BUTTON_BG)->EnableWindow(!m_istransbg);
}



void CSettingsDialog::OnCheckTopAlign() 
{
	((CButton*)GetDlgItem(IDC_CHECK_BOTTOM))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_H))->SetCheck(0);	
}

void CSettingsDialog::OnCheckHeighAlign() 
{
	((CButton*)GetDlgItem(IDC_CHECK_TOP))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_BOTTOM))->SetCheck(0);
	
}

void CSettingsDialog::OnCheckBottomAlign() 
{
	((CButton*)GetDlgItem(IDC_CHECK_TOP))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_H))->SetCheck(0);	
}

void CSettingsDialog::OnCheckLeftAlign() 
{
	((CButton*)GetDlgItem(IDC_CHECK_EDGEWISE))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_RIGHT))->SetCheck(0);
}

void CSettingsDialog::OnCheckRightAlign() 
{
	((CButton*)GetDlgItem(IDC_CHECK_LEFT))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_EDGEWISE))->SetCheck(0);
}

void CSettingsDialog::OnCheckEdgewiseAlign() 
{
	((CButton*)GetDlgItem(IDC_CHECK_LEFT))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_RIGHT))->SetCheck(0);
}

void CSettingsDialog::OnOK() 
{

	UpdateData(TRUE);



	if ((((CButton*)GetDlgItem(IDC_CHECK_LEFT))->GetCheck())==1) m_Halign=ALIGN_LEFT;
	if (((CButton*)GetDlgItem(IDC_CHECK_RIGHT))->GetCheck()==1) m_Halign=ALIGN_RIGHT;
	if (((CButton*)GetDlgItem(IDC_CHECK_EDGEWISE))->GetCheck()==1) m_Halign=ALIGN_EDGEWISE;

	if ((((CButton*)GetDlgItem(IDC_CHECK_TOP))->GetCheck())==1) m_Valign=ALIGN_TOP;
	if (((CButton*)GetDlgItem(IDC_CHECK_BOTTOM))->GetCheck()==1) m_Valign=ALIGN_BOTTOM;
	if (((CButton*)GetDlgItem(IDC_CHECK_H))->GetCheck()==1) m_Valign=ALIGN_EDGEWISE;


	m_isPlas=(((CButton*)GetDlgItem(IDC_RADIO_PLAS))->GetCheck()==1);

	double f;
	
	f=atof(m_rot);

	if (((CButton*)GetDlgItem(IDC_RADIO_CLOCKWISE))->GetCheck()==1)
	{	m_rotation=(int)(f*10);
	} else
	{	m_rotation=(int)((-f)*10);
	}

	m_Date=m_Adate.Format(LoadString(IDS_DATEFORMAT));

	CDialog::OnOK();
}


